
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBWeChatPopPage/YBWeChatPopPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBCommonToast/YBCommonToastPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBXieGangAdModule/YBWangGeYuanPage/YBWangGeYuanSubPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBUtils/YBBaseUtils/YBBaseGongNengUtils.dart';
import 'YBWangGeYuanYaoQingPage.dart';

class YBWangGeYuanPage extends StatelessWidget {
  GlobalKey _globalKey = GlobalKey();


  @override
  Widget build(BuildContext context) {
    return Container(
        child: Scaffold(
          body: CustomScrollView(
            slivers: <Widget>[
              SliverAppBar(
                title: Text('斜杠青年'),
                expandedHeight: YBTextStyle.adapterSize280,
                elevation: 0,
                pinned: true,
                flexibleSpace: FlexibleSpaceBar(
                  background: Container(
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                          begin: Alignment.topCenter,
                          end: Alignment.bottomCenter,
                          colors: [
                            YBColor.xieGangQianNianGradientFromColor,
                            YBColor.xieGangQianNianGradientToColor,
                          ]
                      ),
                    ),
                    child: Padding(
                      padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                      child: Column(
                        children: [
                          Container(
                            height: YBTextStyle.adapterSize84,
                          ),
                          Container(
                            child: Image.asset(YBImageStyle.getImagePath('wanggeyuan_headerImageView')),
                          ),
                          Container(
                            height: YBTextStyle.adapterSize20,
                          ),
                          Container(
                            child: Image.asset(YBImageStyle.getImagePath('wanggeyuan_guoneizhiming')),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
              SliverToBoxAdapter(
                child: Padding(
                  padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                  child: Container(
                    height: YBTextStyle.adapterSize326,
                    decoration: BoxDecoration(
                      color: YBColor.white,
                      borderRadius: BorderRadius.only(topLeft: Radius.circular(16.0),topRight: Radius.circular(16.0)),
                      border: Border.all(width: 0.5,color: YBColor.white),
                    ),
                    child: Column(
                      children: [
                        Container(height: 20,),
                        Container(
                          child: Text("· 斜杠青年工作任务 ·",style: YBTextStyle.xieGangQingNianGongzuoRenWuText,),
                        ),
                        Container(height: 30.0,),
                        Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceAround,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              YBWangGeYuanSubPage(imageStr: "xiegangqingnian_wajueqianke",titleStr: "挖掘潜客商机",subTitleStr: "轻松提交，赚每单奖励金",),
                              YBWangGeYuanSubPage(imageStr: "xiegangqingnian_cuoheyuanqu",titleStr: "撮合园区合作",subTitleStr: "资源变现，更享长期收益",),
                            ],
                          ),
                        ),
                        Container(height: 39.0,),
                        Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceAround,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              YBWangGeYuanSubPage(imageStr: "xiegangqingnian_xianxiaguanggao",titleStr: "线下广告落地",subTitleStr: "合作共赢，每月固定收益物卡",),
                              YBWangGeYuanSubPage(imageStr: "xiegangqiannian_xiezhuhuodong",titleStr: "协助活动执行",subTitleStr: "交流学习，即时提取佣金",),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
              SliverToBoxAdapter(
                child: Container(
                  color: YBColor.commonPageBackGroundColor,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: [
                      Container(
                        height: 24,
                      ),
                      Container(
                        child: Image.asset(YBImageStyle.getImagePath("xiegangqingnian_title"),height: 50,),
                      ),
                      Container(
                        height: 12,
                      ),
                    ],
                  ),
                ),
              ),
              SliverToBoxAdapter(
                child: Container(
                  child: Column(
                    children: [
                      Container(
                        height: 20,
                      ),
                      Container(
                        child: Text("· 第一步：邀请3个好友 ·",style: YBTextStyle.xieGangQingNianGongzuoRenWuText),
                      ),
                    ],
                  ),
                ),
              ),
              SliverToBoxAdapter(
                child:Container(
                  height: 24.0,
                ),
              ),
              SliverToBoxAdapter(
                child: Padding(
                  padding: EdgeInsets.only(left: 20,right: 20),
                  child: Container(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        InkWell(
                          child: YBWangGeYuanYaoQingPage(imageStr: "xiegangqingnian_plus",titleStr: "邀请好友",textStyleInfo: YBTextStyle.xieGangQingNianFuBiaoTiText,),
                          onTap: () {
                            YBWeChatPopPage.showWeChatPopPage(context);
                          },
                        ),
                        InkWell(
                          child: YBWangGeYuanYaoQingPage(imageStr: "xiegangqingnian_plus",titleStr: "邀请好友",textStyleInfo: YBTextStyle.xieGangQingNianFuBiaoTiText,),
                          onTap: () {
                            YBWeChatPopPage.showWeChatPopPage(context);
                          },
                        ),
                        InkWell(
                          child: YBWangGeYuanYaoQingPage(imageStr: "xiegangqingnian_plus",titleStr: "邀请好友",textStyleInfo: YBTextStyle.xieGangQingNianFuBiaoTiText,),
                          onTap: () {
                            YBWeChatPopPage.showWeChatPopPage(context);
                          },
                        ),
                      ],
                    ),
                  ),
                ),
              ),
              SliverToBoxAdapter(
                child:Container(
                  height: 24.0,
                ),
              ),
              SliverToBoxAdapter(
                child: Container(
                  height: 44,
                  child: Padding(
                    padding: EdgeInsets.only(left: 50,right: 50),
                    child: MaterialButton(
                        shape: RoundedRectangleBorder(
                          side: BorderSide.none,
                          borderRadius: BorderRadius.all(Radius.circular(22.0)),
                        ),
                        color: YBColor.commonThemeColor,
                        child: Text("邀请3人，立即成为网格员",style: YBTextStyle.xieGangQingNianTuiGuangYuanBtnText,),
                        onPressed:(){
                          YBWeChatPopPage.showWeChatPopPage(context);
                        }),
                  ),
                ),
              ),
              SliverToBoxAdapter(
                child:Container(
                  height: 12.0,
                ),
              ),
              SliverToBoxAdapter(
                child: Container(
                  alignment: Alignment.center,
                  child: Text("邀请好友下载掌上蚁集App并登陆，即可成功",style: YBTextStyle.xieGangQingNianDisPlayText,),
                ),
              ),
              SliverToBoxAdapter(
                child:Container(
                  height: 24.0,
                ),
              ),
              SliverToBoxAdapter(
                child:Container(
                  color: YBColor.commonPageBackGroundColor,
                  height: 12.0,
                ),
              ),
              SliverToBoxAdapter(
                child: Container(
                  child: Column(
                    children: [
                      Container(
                        height: 20,
                      ),
                      Container(
                        child: Text("·第二步，申请加微信群·",style: YBTextStyle.xieGangQingNianGongzuoRenWuText),
                      ),
                      Container(
                        height: 24,
                      ),
                      Container(
                        child: Image.asset(YBImageStyle.getImagePath('mine_gongchonghao',format: 'jpg'),height: 200,width: 200,),
                      ),
                      Container(
                        height: 16.0,
                      ),
                      Container(
                        child: MaterialButton(
                            height: 36,
                            minWidth: 144,
                            shape: RoundedRectangleBorder(
                              side: BorderSide.none,
                              borderRadius: BorderRadius.all(Radius.circular(18.0)),
                            ),
                            color: YBColor.commonThemeColor,
                            child: Text("保存图片",style: YBTextStyle.xieGangQingNianBaoCunWhiteText,),
                            onPressed: (){
                              print('保存图片');
                              _requestPermission();
                              _saveScreen();
                            }),
                      ),
                      Container(
                        height: 24,
                      ),
                      Container(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Container(
                              child: Text("群主微信号:",style: YBTextStyle.xieGangQingNianDisPlayText),
                            ),
                            Container(
                              width: 8,
                            ),
                            Container(
                              child: Text("13750888602"),
                            ),
                            Container(
                              width: 8,
                            ),
                            Container(
                              child: InkWell(
                                child: Text("复制",style:YBTextStyle.xieGangQingNianFuZhiText,),
                                onTap: (){
                                  YBBaseGongNengUtils.setDataMsg("13750888602");
                                },
                              ),
                            ),
                            Container(
                              width: 3,
                            ),
                            Container(
                              child: Image.asset(YBImageStyle.getImagePath('lawyerImage_IconСolor'),width: 10,height: 10,),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              SliverToBoxAdapter(
                child: Container(
                  height: 32,
                ),
              ),
              SliverToBoxAdapter(
                child: Container(
                  alignment: Alignment.center,
                  child: Text("进群后联系群主会有审核专人审核后",style: YBTextStyle.xieGangQingNianDisPlayText),
                ),
              ),
              SliverToBoxAdapter(
                child: Container(
                  alignment: Alignment.center,
                  child: Text("免费成为E办事斜杠青年",style: YBTextStyle.xieGangQingNianDisPlayText),
                ),
              ),
              SliverToBoxAdapter(
                child: Container(
                  height: 24,
                ),
              ),
            ],
          ),
        ),
    );
  }


  _requestPermission() async {
    Map<Permission, PermissionStatus> statuses = await [
      Permission.storage,
    ].request();
    final info = statuses[Permission.storage].toString();
    print(info);
  }

  _saveScreen() async {
    ByteData byteData = await rootBundle.load(YBImageStyle.getImagePath('mine_gongchonghao',format: 'jpg'));
    final result = await ImageGallerySaver.saveImage(byteData.buffer.asUint8List());
    print('--------${result.toString()}------');
    if (result.toString().isNotEmpty) {
       YBToast.showToastInfo("保存成功");
    } else {
       YBToast.showToastInfo("保存失败");
    }
  }

}
